package com.heima.comment.controller.v1;

import com.heima.comment.service.CommentService;
import com.heima.model.comment.dtos.CommentDTO;
import com.heima.model.comment.dtos.CommentLikeDTO;
import com.heima.model.comment.dtos.CommentSaveDTO;
import com.heima.model.comment.vo.ApCommentVo;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.validator.ValidatorAdd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {


    @Autowired
    private CommentService commentService;

    /**
     * 保存评论
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody  @Validated({ValidatorAdd.class}) CommentSaveDTO dto){
        return commentService.saveComment(dto);
    }

    /**
     * 点赞评论
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody   @Validated(ValidatorAdd.class) CommentLikeDTO dto){
        return commentService.like(dto);
    }

    /**
     * 根据文章id查询评论列表
     * @return
     */
    @PostMapping("/load")
    public ResponseResult findByArticleId(@RequestBody   CommentDTO dto){

        return commentService.findByArticleId(dto);
    }
}
